<template>
	<view class="cyq-grid">
		<view class="list">
			<view v-for="(item, index) in dataList" :key="index" class="item" :style="{width: colWidth}"
				@click="clickItem(item)">
				<image :src="item.src"></image>
				<view class="title" :style="{color: textColor}">
					{{item.title}}{{index % 2 === 0 ?  index+'标题标题标题' :index + '标题'}}
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		props: {
			dataList: {
				type: Array,
				default: () => []
			},
			col: {
				type: Number,
				default: 5,
			},
			textColor: {
				type: String,
				default: '#000'
			}
		},
		watch: {
			col: {
				handler(newValue, oldValue) {
					if (newValue > 6) {
						this.colWidth = 100 / 6 + '%'
					} else if (newValue < 3) {
						this.colWidth = 100 / 3 + '%'
					} else {
						this.colWidth = 100 / newValue + '%'
					}
				},
				immediate: true
			}
		},
		data() {
			return {
				colWidth: ''
			}
		},

		onLoad() {},
		methods: {
			clickItem(item) {
				this.$emit('clickItem', item)
			}
		}
	}
</script>

<style lang="scss" scoped>
	.cyq-grid {
		.list {
			display: flex;
			flex-wrap: wrap;
			padding: 10px 0;

			.item {
				text-align: center;
				padding: 5px 0px;
				height: 100%;

				image {
					width: 88rpx;
					height: 88rpx;
				}

				.title {
					text-align: center;
					line-height: 20px;
					word-wrap: break-word;
				}
			}
		}
	}
</style>
